# test_db.py
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from models.user_models import Patient  # 确保你已经定义了 User 模型
from database import Base  # 包含 create_engine 和 Base
import config

# 替换成你自己的数据库信息
DATABASE_URL = config.DATABASE_URL

engine = create_engine(DATABASE_URL)
SessionLocal = sessionmaker(bind=engine)
session = SessionLocal()

# patient

try:
    # 查询前5个用户
    patients = session.query(Patient).limit(5).all()
    for patient in patients:
        print(patient.ID, patient.姓名, patient.电话)
except Exception as e:
    print("查询失败：", e)
finally:
    session.close()
